package com.example.teesystem.filter;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class CustomWevMvcConfigure implements WebMvcConfigurer {
    private final MyHandlerInterceptor myHandlerInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myHandlerInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/tee/user/getSalt", "/tee/user/login", "/tee/user/register", "/tee/test/**")
                .excludePathPatterns("/pk-socket/**")
        ;
    }
    
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("token", "uid")
                .exposedHeaders("token", "uid")
                .allowCredentials(true).maxAge(3600);
    }
}
